package com.climber.android.commonres.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.viewpager.widget.ViewPager;


public class ScrollControlViewPager extends ViewPager {
	private final String TAG = ScrollControlViewPager.class.getSimpleName();
	private boolean scroll = true;

	public ScrollControlViewPager(Context context) {
		super(context);
	}

	public ScrollControlViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	/**
	 * @param scroll
	 */
	public void setScroll(boolean scroll) {
		this.scroll = scroll;
	}

	@Override
	public void scrollTo(int x, int y) {
		super.scrollTo(x, y);
	}

	@Override
	public boolean onTouchEvent(MotionEvent arg0) {
		try {
			return scroll && super.onTouchEvent(arg0);
		} catch (IllegalArgumentException ex) {
			ex.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent arg0) {
		try {
			return scroll && super.onInterceptTouchEvent(arg0);
		} catch (IllegalArgumentException ex) {
			ex.printStackTrace();
		}
		return false;
	}

	@Override
	public void setCurrentItem(int item, boolean smoothScroll) {
		super.setCurrentItem(item, smoothScroll);
	}

	@Override
	public void setCurrentItem(int item) {
		super.setCurrentItem(item);
	}
}
